package org;

import org.dom4j.DocumentException;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

import static trace.tarce1.trace1;
import static trace.tarce1local.trace1local;

public class Main {

    public static void main(String[] args) throws SchedulerException {
        trace1();
//        trace1local();
        // 定义JobDetail
//        JobDetail job = JobBuilder.newJob(MyDailyJob.class)
//                .withIdentity("myDailyJob", "group1")
//                .build();
//
//        // 定义Trigger，设定为每天凌晨4点执行
//        Trigger trigger = TriggerBuilder.newTrigger()
//                .withIdentity("myDailyTrigger", "group1")
//                .withSchedule(CronScheduleBuilder.dailyAtHourAndMinute(4, 0))
//                .build();
//
//        // 获取Scheduler实例
//        Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
//
//        // 开始调度器
//        scheduler.start();
//
//        // 将Job和Trigger加入调度器
//        scheduler.scheduleJob(job, trigger);
    }

    // 定义需要定时执行的任务
    public static class MyDailyJob implements Job {
        @Override
        public void execute(JobExecutionContext context) throws JobExecutionException {
            // 在此处调用你需要每天执行的方法
            try {
                performDailyTask();
            } catch (DocumentException e) {
                throw new RuntimeException(e);
            }
        }

        private void performDailyTask() throws DocumentException {
           trace1();
        }
    }
}